<?php

class payments_Controller extends Controller {
    
    public function _default($params) {
        $view = new payments_View(new Module((int)$params['module']));
        if(isset($params['uid'])) {
            $user = new AnyUser((int)$params['uid']);
            if($user->getUid() > 0) {
                $view->createView('showUserInfo', array_merge($params,array('user'=>$user)));
            } else {
                $view->createView('chooseUserError', $params);
            }
        } else {
            $view->createView('menu',$params);
        }
        return $view;
    }
    
    public function money($params) {
        $view = new payments_View(new Module((int)$params['module']));
        if(isset($params['uid'])) {
            if(isset($_POST['rates'])) {
                $user = new AnyUser((int)$params['uid']);
                $rates = (object) $_POST['rates'];
                if(UserDAO::setRates($user, $rates)) {
                    $view->createView('setUserRatesSuccess',$params);
                } else {
                    $view->createView('setUserRatesError',array_merge($params,array('user'=>$user)));
                }
            } else {
                $user = new AnyUser((int)$params['uid']);
                if($user->getUid() > 0) {
                    $view->createView('moneyInfo', array_merge($params,array('user'=>$user)));
                } else {
                    $view->createView('chooseUserError', $params);
                }
            }
        } else {
            $view->createView('menu',$params);
        }
        return $view;
    }
    
    public function hours($params) {
        $view = new payments_View(new Module((int)$params['module']));
        if(isset($params['uid'])) {
            if(isset($_POST['hours'])) {
                $user = new AnyUser((int)$params['uid']);
                $hours = $_POST['hours'];
                if(UserDAO::setHoursWeekly($user, $hours)) {
                    $view->createView('setUserHoursSuccess',$params);
                } else {
                    $view->createView('setUserHoursError',array_merge($params,array('user'=>$user)));
                }
            } else {
                $user = new AnyUser((int)$params['uid']);
                if($user->getUid() > 0) {
                    $view->createView('hours', array_merge($params,array('user'=>$user)));
                } else {
                    $view->createView('chooseUserError', $params);
                }
            }
        } else {
            $view->createView('menu',$params);
        }
        return $view;
    }
    
    public function payment($params) {
        $view = new payments_View(new Module((int)$params['module']));
        if(isset($params['uid'])) {
            $user = new AnyUser((int)$params['uid']);
            if($user->getUid() > 0) {
                $view->createView('payment', array_merge($params,array('user'=>$user)));
            } else {
                $view->createView('chooseUserError', $params);
            }
        } else {
            $view->createView('menu',$params);
        }
        return $view;   
    }
}

?>
